// Copyright (c) 2024, lanlian and contributors
// For license information, please see license.txt

frappe.ui.form.on("EMS External Maintenance", {
	refresh(frm) {
        // 故障维修单下推验收结算单
        frm.add_custom_button(__('Make EMS Acceptance Settlement'), () => {
            frappe.model.open_mapped_doc({
                method: "ems.equipment_managerment_system.doctype.ems_external_maintenance.ems_external_maintenance.make_acceptance_settlement",
                frm: cur_frm,
                freeze_message: __("Creating Task ...")
            });
        });
	},
    amount_include_tax: function(frm) {
        frm.set_value('amount_no_tax', frm.doc.amount_include_tax / (1 + frm.doc.tax_rate/100) );
        frm.set_value('tax_amount', frm.doc.amount_include_tax - frm.doc.amount_include_tax / (1 + frm.doc.tax_rate/100) );
        frm.refresh_field('amount_no_tax');frm.refresh_field('tax_amount');
    },
    tax_rate: function(frm) {
        frm.set_value('amount_no_tax', frm.doc.amount_include_tax / (1 + frm.doc.tax_rate/100) );
        frm.set_value('tax_amount', frm.doc.amount_include_tax - frm.doc.amount_include_tax / (1 + frm.doc.tax_rate/100) );
        frm.refresh_field('amount_no_tax');frm.refresh_field('tax_amount');
    },
});
